#!/bin/ksh

function exit_routine
{
  [[ -n "$telnet_pid" ]] && kill -s TERM $telnet_pid
  print "timeout-reached"
}

#wait for broadcast
trap exit_routine ALRM

curr_shell_pid=$$
(
  #wake up after # of seconds
  sleep 8
  #broadcast kill
  kill -s ALRM $curr_shell_pid
) &
alarm=$!

/home/notroot/scripts/telnet.ksh &
telnet_pid=$!

print "telnet pid = $telnet_pid"

wait $telnet_pid
kill -s TERM $alarm >/dev/null 2>&1

exit 0
